import { Form, Input, Select } from 'antd'
import React, { Component, } from 'react'
const Item = Form.Item
const Option = Select.Option
export default class Adduser extends Component {
  onFinish = (value) => {
    return value
  }

  render() {
    const { roles, record, Modaltitle,register } = this.props
    console.log(this.props, roles, record, Modaltitle );
    let username, phone, email, role_id
    if (Modaltitle === 1 && record !== undefined) {
      username = record.username
      phone = record.phone
      email = record.email
      role_id = record.role_id
    }

    return (
      <Form name='addusesr' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}
        onFinish={this.onFinish} ref={this.props.AdduserRef}
        initialValues={{ username, phone, email, role_id }}
        preserve={false}>
        <Item name='username' label='用户名' rules={[
          { required: true, message: '用户名必须填写！' }
        ]}>
          <Input placeholder='请输入用户名'></Input>
        </Item>
        <Item name='password' label='密码' rules={[
          { required: Modaltitle===0, message: '密码名必须填写！' }
        ]}>
          <Input type='password' placeholder={Modaltitle===0?'请输入密码':'不修改密码可不填写'}></Input>
        </Item>
        <Item name='phone' label='手机号' >
          <Input type='tel' placeholder='请输入手机号'></Input>
        </Item>
        <Item name='email' label='邮箱' rules={[
          { type: 'email', message: '请输入邮箱' }
        ]}>
          <Input type='email' placeholder='请输入邮箱'></Input>
        </Item>
        <Item name='role_id' label='角色' >
          <Select placeholder={roles.length === 0 ? (register===0?'当前无角色':'未登录无权限设置角色') : '请选择角色'}>
            {
              roles.map((item) => {
                return (
                  <Option key={item._id} children={item.name} />
                )
              })}
          </Select>
        </Item>
      </Form>
    )
  }
}